package Help.Log;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import sft.BancodeDados.CriaConexao;

public class HistoricoDao {

    private static Connection conexao;
    
    public HistoricoDao() throws SQLException {
        conexao = new CriaConexao().getConnection();
    }
    
    public List<Historico> getConnection(int caso, Historico h) throws SQLException{
        String sql = "select * from sft_log";
    
        if(caso == 1){
            sql = "select * from sft_log l "
                    + "where l.log_dt_dtlog>= ? "
                    + "and l.log_dt_dtlog <= ? "
                    + "ORDER BY l.log_dt_dtlog";
        }
        PreparedStatement stmt = conexao.prepareStatement(sql);
        
        if(caso == 1){
            stmt.setString(1, h.getInicial());
            stmt.setString(2, h.getFinal());
        }
        ResultSet rs = stmt.executeQuery();
        
        List<Historico>  minhaLista = new ArrayList<>();
        
        while (rs.next()) {            
            Historico h1 = new Historico();
            h1.setUser(rs.getString("log_nm_nmlog"));
            h1.setAcao(rs.getString("log_ac_aclog"));
            h1.setData(rs.getString("log_dt_dtlog"));
            minhaLista.add(h1);
        }
        
        return minhaLista;
    }
}
